package org.gwt.pluginframework.desktop.client;

import org.gwt.pluginframework.common.Plugin;
import org.gwt.pluginframework.common.event.IPluginEvent;
import org.gwt.pluginframework.common.event.PluginEvent;
import org.gwt.pluginframework.common.event.PluginEventHandler;
import org.gwt.pluginframework.plugin.CustomEvents;

public class FormCFactory extends Plugin {
	private static final long serialVersionUID = -6846780914468768873L;

	public static final String CREATE_FORMC_PLUGIN_EVENT = "createFormCPluginEvent";
	
	private Long sequence = 1L;
	
	public void setupManifest() {
		manifest.setName("FormCFactory");
		manifest.setVersion("1.0");
	}
	
	@Override
	public void onInitialize() {
		registerEventHandler(new PluginEventHandler(CREATE_FORMC_PLUGIN_EVENT) {
			public void handle(IPluginEvent event) {
				FormC plugin = new FormC(sequence.toString());
				sequence++;
				manager.registerPlugin(plugin);
				plugin.initialize();
				plugin.start();
				dispatch(new PluginEvent(CustomEvents.START_TAB_EVENT, 
						new String[] { "tabItem" }, 
						new Object[] { plugin.getTabItem() }));
			}
		});
	}
}
